import Vue from 'vue'
import VueRouter from 'vue-router'
// 静态导入，应用启动时，相关模块会被立即加载和解析
import Layout from '@/views/layout/Index'
import Login from '@/views/login/Index'
import Home from '@/views/home/Home'

// 动态导入（也叫按需导入），模块在需要时（路由被访问时）才会加载
const Product = ()=> ('@/views/product/Index.vue') 
const ProductList = ()=> ('@/views/product/list/List.vue') 
const ProductCategory = ()=> ('@/views/product/category/Category.vue') 

const Order = ()=> ('@/views/order/Index.vue') 
const OrderList = ()=> ('@/views/order/list/List.vue') 
const OrderDetails = ()=> ('@/views/order/details/Details.vue') 

const Advertisement = ()=> ('@/views/advertisement/Index.vue') 
const AdvertisementList = ()=> ('@/views/advertisement/list/List.vue') 


Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    component:Layout,
    children:[   /* 二级路由 */
      {
        path:'/',
        name:"home",
        component:Home
      },
      {
        path:'/product',  /* 产品列表 */
        name:"product",
        component:Product,
        children:[  /* 三级路由 */
          {
            path:'product-list',
            name:"product-list",
            component:ProductList
          },
          {
            path:'category',
            name:"category",
            component:ProductCategory
          }
        ]
      },
      {
        path:'/Order',   /* 订单列表 */
        name:"order",
        component:Order,
        children:[  
          {
            path:'order-list',
            name:"order-list",
            component:OrderList
          },
          {
            path:'order-details',
            name:"order-details",
            component:OrderDetails
          }
        ]
      },
      {
        path:'/advertisement',   /* 广告列表 */
        name:"advertisement",
        component:Advertisement,
        children:[  
          {
            path:'advertisement-list',
            name:"advertisement-list",
            component:AdvertisementList
          }
        ]
      }
    ]
  },
  {
    path:'/login',
    name:'login',
    component:Login
  }
]

const router = new VueRouter({
  routes
})

export default router
